﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace RenjianImageViewer.DataModel
{
    class StatusModel
    {
        private long id;
        private bool truncated = false;
        private long replyToStatusId;
        private long replyToUserId;
        private string replyToUserScreenName;
        private long forwardStatusId;
        private string forwardUserScreenName;

        public string CreateTime { get; private set; }
        public string Text { get; private set; }
        public string Source { get; private set; }
        public bool Favorited { get; private set; }
        public /*StatusType*/ string Type { get; private set; }
        public string OriginalUrl { get; private set; }
        public string Thumbnail { get; private set; }
        public string LinkTitle { get; private set; }
        public string LinkDescription { get; private set; }
        public string AppName { get; private set; }
        public UserModel User { get; private set; }
        public string SingleLineText
        {
            get
            {
                return Text.Replace("\n", " ");
            }
        }

        public StatusModel(string xmlString) :
            this(XElement.Parse(xmlString))
        {
        }

        public StatusModel(XElement statusElement)
        {
            id = (long)statusElement.Element("id");
            truncated = (bool)statusElement.Element("truncated");
            //replyToStatusId = (long)statusElement.Element("in_reply_to_status_id");
            //replyToUserId = (long)statusElement.Element("in_reply_to_user_id");
            //replyToUserScreenName = statusElement.Element("in_reply_to_screen_name").Value;
            //forwardStatusId = (long)statusElement.Element("in_forward_status_id");
            //forwardUserScreenName = statusElement.Element("in_forward_screen_name").Value;

            CreateTime = statusElement.Element("created_at").Value;
            Text = statusElement.Element("text").Value;
            if (string.IsNullOrEmpty(Text))
            {
                Text = "分享了图片";
            }
            Source = statusElement.Element("source").Value;
            Favorited = (bool)statusElement.Element("favorited");
            Type = statusElement.Element("status_type").Value;
            OriginalUrl = statusElement.Element("original_url").Value;
            Thumbnail = statusElement.Element("thumbnail").Value;
            LinkTitle = statusElement.Element("link_title").Value;
            LinkDescription = statusElement.Element("link_desc").Value;
            //AppName = statusElement.Element("app_name").Value;
            User = new UserModel(statusElement.Element("user"));
        }
    }

    enum StatusType
    {
        Text,
        Picture,
        Link
    }
}
